class_name Camera
extends Camera2D


## 球被持有时相机的偏移量
@export var offset_carried: float = 100.0
## 持球时的平滑速度
@export var smoothing_speed_carried: float = 2.0
## 默认的平滑速度
@export var smoothing_speed_default: float = 8.0


# 球的引用
var ball: Ball


func _ready():

	await get_tree().process_frame
	ball = Sundry.find_ball(get_tree())




func _process(_delta: float):
	if ball:
		follow_ball()



func follow_ball():
	if ball.carrier:
		position = ball.position + ball.carrier.character_direction() * offset_carried
		position_smoothing_speed = smoothing_speed_carried
	else:
		position = ball.position
		position_smoothing_speed = smoothing_speed_default
